package com.hongxun.project.assets.kBj.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.hongxun.framework.aspectj.lang.annotation.Log;
import com.hongxun.framework.aspectj.lang.enums.BusinessType;
import com.hongxun.project.assets.kBj.domain.KBj;
import com.hongxun.project.assets.kBj.service.IKBjService;
import com.hongxun.framework.web.controller.BaseController;
import com.hongxun.framework.web.page.TableDataInfo;
import com.hongxun.framework.web.domain.AjaxResult;
import com.hongxun.common.utils.poi.ExcelUtil;

/**
 * 计-扩展 信息操作处理
 * 
 * @author hongxun
 * @date 2019-06-25
 */
@Controller
@RequestMapping("/assets/kBj")
public class KBjController extends BaseController
{
    private String prefix = "assets/kBj";
	
	@Autowired
	private IKBjService kBjService;
	
//	@RequiresPermissions("assets:kBj:view")
	@GetMapping()
	public String kBj()
	{
	    return prefix + "/kBj";
	}
	
	/**
	 * 查询计-扩展列表
	 */
//	@RequiresPermissions("assets:kBj:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(KBj kBj)
	{
		startPage();
        List<KBj> list = kBjService.selectKBjList(kBj);
		return getDataTable(list);
	}
	
	
	/**
	 * 导出计-扩展列表
	 */
	@RequiresPermissions("assets:kBj:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(KBj kBj)
    {
    	List<KBj> list = kBjService.selectKBjList(kBj);
        ExcelUtil<KBj> util = new ExcelUtil<KBj>(KBj.class);
        return util.exportExcel(list, "kBj");
    }
	
	/**
	 * 新增计-扩展
	 */
	@GetMapping("/add")
	public String add()
	{
	    return prefix + "/add";
	}


	@GetMapping("/addForDeviceId")
	public String addForDeviceId(KBj kBj , ModelMap modelMap)
	{
		modelMap.put("newByqId",kBj.getByqId());
		modelMap.put("newPointId",kBj.getPId());
		modelMap.put("newDeviceId",kBj.getBoxId());
	    return prefix + "/addForDeviceId";
	}
	
	/**
	 * 新增保存计-扩展
	 */
	@RequiresPermissions("assets:kBj:add")
	@Log(title = "计-扩展", businessType = BusinessType.INSERT)
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(KBj kBj)
	{		
		return toAjax(kBjService.insertKBj(kBj));
	}

	/**
	 * 修改计-扩展
	 */
	@GetMapping("/edit/{id}")
	public String edit(@PathVariable("id") String id, ModelMap mmap)
	{
		KBj kBj = kBjService.selectKBjById(id);
		mmap.put("kBj", kBj);
	    return prefix + "/edit";
	}

	//	修改电能表
	@GetMapping("/editForDeviceId/{id}")
	public String editForDeviceId(@PathVariable("id") String id, ModelMap mmap)
	{
		KBj kBj = new KBj();
		kBj.setBoxId(id);
		List<KBj> kBjList = kBjService.selectKBjList(kBj);
		mmap.put("kBj", kBjList.get(0));
	    return prefix + "/editForDeviceId";
	}
	
	/**
	 * 修改保存计-扩展
	 */
	@RequiresPermissions("assets:kBj:edit")
	@Log(title = "计-扩展", businessType = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(KBj kBj)
	{		
		return toAjax(kBjService.updateKBj(kBj));
	}
	
	/**
	 * 删除计-扩展
	 */
//	@RequiresPermissions("assets:kBj:remove")
	@Log(title = "计-扩展", businessType = BusinessType.DELETE)
	@PostMapping( "/remove")
	@ResponseBody
	public AjaxResult remove(String ids)
	{		
		return toAjax(kBjService.deleteKBjByIds(ids));
	}
	
}
